package com.sunny.原子性.AtomicReference原子性引用;

import com.sunny.anotation.ThreadSafe;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.atomic.AtomicReference;

@Slf4j
@ThreadSafe
public class AtomicRefenrenceTest {
    private static AtomicReference<Integer> integerAtomicReference = new AtomicReference<>(0);

    public static void main(String[] args) {
        integerAtomicReference.compareAndSet(0, 2); // 2
        integerAtomicReference.compareAndSet(2, 4); // 4
        integerAtomicReference.compareAndSet(4, 6); // 6
        integerAtomicReference.compareAndSet(0, 2); // no
        integerAtomicReference.compareAndSet(2, 7); // no
        log.info("count:{}", integerAtomicReference);
    }
}
